const app = getApp();
import util from '../../../utils/util'
import {
  ImportantMemberCount,
  AdminImportMember
} from '../../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isEmpty: false,
    adminInfo: '',
    grider_storge: '',
    person_mark_arr: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let adminInfo = wx.getStorageSync('adminInfo')
    let grider_storge = wx.getStorageSync('grider')
    this.setData({
      adminInfo,
      grider_storge
    })

    if (adminInfo){ // 判断管理员
      this.getAdminImptMemList()
    }else{
      this.getImportCount();
    }

    
  },

  getAdminImptMemList() { // 获取管理员统计
    let that = this;
    util.apiRequest(AdminImportMember, {
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('管理员：',r)
      if (r.data.data.length == 0) {
        that.setData({
          isEmpty: true
        })
      }
      that.setData({
        person_mark_arr: r.data.data
      })
    })
  },

  getImportCount() { // 获取网格统计列表
    let that = this;
    let params = {
      grider_id: this.data.grider_storge.id,
      vollege_id: app.globalData.vollege_id
    }
    util.apiRequest(ImportantMemberCount, params, null).then(r => {
      console.log('人员统计：', r)
      if (r.data.data.length == 0) {
        that.setData({
          isEmpty: true
        })
      }
      that.setData({
        person_mark_arr: r.data.data
      })
    })
  },

  toDetail(e) {
    console.log(e)
    let tags_id = e.currentTarget.dataset.tags_id;
    console.log('tags_id:', tags_id)
    wx.navigateTo({
      url: '/pages/grid/key_person_detail/key_person_detail?tags_id=' + tags_id
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})